package com.xique.door.project.miniprogram.biz.service.impl;

import com.xique.common.core.utils.SecurityUtils;
import com.xique.common.core.utils.StringUtils;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.door.bean.domain.BaseUserV1;
import com.xique.door.bean.domain.UserV1;
import com.xique.door.project.miniprogram.bean.vo.MiniUserInfoVO;
import com.xique.door.project.miniprogram.biz.service.IMiniMineBizService;
import com.xique.door.service.IBaseUserService;
import com.xique.door.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author shd
 * @create 2022/4/15 14:40
 */
@Service
public class MiniMineBizServiceImpl implements IMiniMineBizService {

    @Autowired
    private IBaseUserService baseUserService;

    @Autowired
    private IUserService userService;

    @Override
    public AjaxResult getInfo() {
        Long userId = SecurityUtils.getBaseUserId();

        BaseUserV1 user = baseUserService.getById(userId);
        if (StringUtils.isNull(user)) {
            return AjaxResult.error("未找到对应用户");
        }

        MiniUserInfoVO vo = new MiniUserInfoVO();
        vo.setBaseUserId(user.getId());
        vo.setUserName(user.getUserName());
        vo.setPhone(user.getCellphone());

        Long parkId = SecurityUtils.getParkId();
        if (StringUtils.isNotNull(parkId)) {
            UserV1 search = new UserV1();
            search.setParkId(parkId);
            search.setBaseUserId(userId);

            UserV1 userV1 = userService.selectUserV1(search);

            if (StringUtils.isNotNull(userV1)) {
                vo.setUserId(userV1.getId());
            }
        }

        return AjaxResult.success(vo);
    }
}
